<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	template="/WEB-INF/template/templateInserimentoOrdineFattura.xhtml">

<!-- Pannello per la creazione dell' ordine -->		

	<!-- Parte descrittiva dell' ordine -->	
	<ui:define name="parteDescrittivaOrdineFattura">
		<fieldset>
		<legend><b>Parte Descrittiva</b></legend>
		<h:panelGrid id="pannelloParteDescrittivaOrdine" border="0"  columns="2">
		
		
			<h:panelGroup >
				<h:outputLabel 		value="Cliente:"  styleClass="labelClass"/>
				<rich:inplaceInput defaultLabel="Cliente" value="#{tab.object.cliente.denominazione}" />
				<a4j:commandButton 	value="cliente" actionListener="#{selectBean.findAllClienti}" oncomplete="#{rich:component('popupRicercaClienti')}.show()"
									render="popupRicercaClienti" styleClass="submitClass"/>
			
			</h:panelGroup>
			
			<h:panelGroup >
				<h:outputLabel 		value="CodiceOrdine :"  styleClass="labelClassCenter" style="margin:left:10px"/>
				<h:inputText value="#{tab.object.codiceOrdine}" style=" width : 69px;"/>
			</h:panelGroup>
			
			<h:panelGroup >
				<h:outputLabel 		value="DataAccettazione"  styleClass="labelClass"/>
				<rich:calendar value="#{tab.object.dataAccettazione}" ></rich:calendar>
			</h:panelGroup>
			
			<h:panelGroup >
				<h:outputLabel 		value="DataConsegna:"  styleClass="labelClassCenter"/>
				<rich:calendar value="#{tab.object.dataConsegna}" ></rich:calendar>
			</h:panelGroup>
			
		</h:panelGrid>
		</fieldset>
		
		<!-- PopUp per la ricerca dei clienti -->
		<rich:popupPanel id="popupRicercaClienti" width="400" height="250" domElementAttachment="parent">
			<f:facet name="header">Ricerca Clienti</f:facet>
			<f:facet name="controls">
			
				<a4j:commandButton 	value="Add" 
									action="#{tab.object.setCliente(selectBean.clienteSelezionato)}" 
									oncomplete="#{rich:component('popupRicercaClienti')}.hide();return false;"
									render="pannelloParteDescrittivaOrdine"  
									/>
				
				<h:outputLink 	value="#"
								style="font-size:large; color:black; textdecoration:none;"
								onclick="#{rich:component('popupRicercaClienti')}.hide();return false;">X
				</h:outputLink>
				
			</f:facet>
			
			<rich:extendedDataTable id="tabellaRicercaClienti"
									value="#{selectBean.clientiAttivi}" var="cliente"
									selection="#{selectBean.selection}"
									selectionMode="#{selectBean.selectionMode}">
												
				<a4j:ajax event="selectionchange" listener="#{selectBean.tableListener}"  /> 

				<rich:column>
					<f:facet name="header">Id</f:facet>
					<h:outputText value="#{cliente.idCliente}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Denominazione</f:facet>
					<h:outputText value="#{cliente.denominazione}" />
				</rich:column>
				
			</rich:extendedDataTable>
			
		</rich:popupPanel>
			
	</ui:define>

	<ui:define name="parteTabellareOrdineFattura">
		
			<fieldset>
			<legend><b>Parte Tabellare</b></legend>
				<h:panelGrid id="pannelloParteTabellareOrdine" border="0">
					<rich:extendedDataTable id="tabellaLineeOrdine" value="#{tab.object.lineeOrdine}" var="lineaOrdine"
											rowKeyVar="rowIndex" rows="5" >
					
					<rich:column>
						<f:facet name="header">Prodotto</f:facet>
						<h:outputText value="#{lineaOrdine.prodotto.descrizione}" />	
					</rich:column>
				
					<rich:column>
						<a4j:commandButton 	value="Prodotto" actionListener="#{selectBean.findAllProdottiAttivi}" 
											oncomplete="#{rich:component('popupRicercaProdotti')}.show()"
											render="popupRicercaProdotti" >
							<a4j:param value="#{rowIndex}" assignTo="#{tabsBean.indiceLineaOrdineSelezionata}"></a4j:param>	
							</a4j:commandButton>
							
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Quantita</f:facet>
						<h:inputText 	id="quantita" value="#{lineaOrdine.quantita}" >
							
							<a4j:ajax event="blur" render="importo pannelloParteRiepilogoOrdine" execute="quantita prezzo iva" listener="#{calcoli.calcolaImportoTotale(lineaOrdine,tab.object)}" />
							
						</h:inputText>
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Prezzo</f:facet>
						<h:inputText id="prezzo" value="#{lineaOrdine.prezzo}" >
							<a4j:ajax event="blur" render="importo pannelloParteRiepilogoOrdine" execute="quantita prezzo iva" listener="#{calcoli.calcolaImportoTotale(lineaOrdine,tab.object)}" />
						</h:inputText>
					</rich:column>
					
					<rich:column width="50px">
						<f:facet name="header" >Iva</f:facet>
						<h:selectOneMenu id="SelezioneIva" value="#{lineaOrdine.iva}">
							<f:selectItem itemLabel="4" itemValue="4" />
        					<f:selectItem itemLabel="10" itemValue="10" />
       				 		<f:selectItem itemLabel="21" itemValue="21" />
       				 			<a4j:ajax event="valueChange" render="importo pannelloParteRiepilogoOrdine" execute="quantita prezzo iva" listener="#{calcoli.calcolaImportoTotale(lineaOrdine,tab.object)}" />
						</h:selectOneMenu>
					</rich:column>
					
					
					
					<ui:remove>
					<rich:column>
						<f:facet name="header">Iva</f:facet>
						<rich:select id="iva" defaultLabel="Iva" value="#{lineaOrdine.iva}">>
							<f:selectItem itemValue="4" itemLabel="4" />
							<f:selectItem itemValue="10" itemLabel="10" />
							<f:selectItem itemValue="21" itemLabel="21" />
							<ui:remove>
							<a4j:ajax event="blur" render="importo pannelloParteRiepilogoOrdine" execute="quantita prezzo iva" listener="#{calcoli.calcolaImportoTotale(lineaOrdine,tab.object)}" />
							</ui:remove>
						</rich:select>
					</rich:column>
					</ui:remove>
					
					<rich:column>
						<f:facet name="header">Importo</f:facet>
						<h:inputText id="importo" value="#{lineaOrdine.importo}" >
							
						</h:inputText>
					</rich:column>
				
					<f:facet name="footer">
							<rich:dataScroller page="#{tab.page}" />
					</f:facet>
					
					
			</rich:extendedDataTable>
			<f:facet name="footer">
			
				<a4j:commandButton 	value="NuovaRiga" action="#{tabsBean.addLineaOrdine()}" render="tabellaLineeOrdine"/>
				<a4j:commandButton 	value="EliminaRiga" action="#{tabsBean.deleteLineaOrdine()}" render="tabellaLineeOrdine">
					<a4j:param value="#{rowIndex}" assignTo="#{tabsBean.indiceLineaOrdineSelezionata}"></a4j:param>
				</a4j:commandButton>
				
			
			
			</f:facet>
			
		
		</h:panelGrid>
	</fieldset>
		
		
	<rich:popupPanel id="popupRicercaProdotti" width="400" height="250" domElementAttachment="parent">
		<f:facet name="header">Ricerca Prodotti</f:facet>
		<f:facet name="controls">
		
			<a4j:commandButton 	value="Add" 
								action="#{tabsBean.addProdottoALineaOrdine(selectBean.prodottoSelezionato)}" 
								oncomplete="#{rich:component('popupRicercaProdotti')}.hide();return false;"
								render="pannelloParteTabellareOrdine"  
								/>
			
			<h:outputLink 	value="#"
							style="font-size:large; color:black; textdecoration:none;"
							onclick="#{rich:component('popupRicercaProdotti')}.hide();return false;">X
			</h:outputLink>
			
		</f:facet>
		
		<rich:extendedDataTable id="tabellaRicercaProdotti"
								value="#{selectBean.prodottiAttivi}" var="prodotto"
								selection="#{selectBean.selection}"
								selectionMode="#{selectBean.selectionMode}">
											
			<a4j:ajax event="selectionchange" listener="#{selectBean.tableListener}"  /> 

			<rich:column>
				<f:facet name="header">Codice Prodotto</f:facet>
				<h:outputText value="#{prodotto.codiceProdotto}" />
			</rich:column>
			
			<rich:column>
				<f:facet name="header">Descrizione</f:facet>
				<h:outputText value="#{prodotto.descrizione}" />
			</rich:column>
			
		</rich:extendedDataTable>
		
	</rich:popupPanel>

		
		
		
		
		
	</ui:define>

	<ui:define name="parteRiepilogoOrdineFattura">
		<fieldset>
			<legend><b>Parte di riepilogo</b></legend>
			
			<h:panelGrid  id="pannelloParteRiepilogoOrdine" columns="3" border="0">
			
				<h:outputText value="Note" />
				<h:inputTextarea value="#{tab.object.note}"  style="width : 297px; height : 65px;" />	
			
				
				<h:panelGroup>
					<h:panelGrid  columns="2" border="0" style=" width : 256px;">
				
						<h:outputText 	value="Tipo Pagamento" />
						<h:selectOneMenu id="SelezioneTipoPagemento" value="#{tab.object.tipoPagamento}" style=" width : 126px;">
							<f:selectItem itemLabel="Assegno" itemValue="Assegno" />
        					<f:selectItem itemLabel="Contanti" itemValue="Contanti" />
						</h:selectOneMenu>
						
						<h:outputText 	value="Stato" />
						<h:selectOneMenu id="SelezioneStato" value="#{tab.object.stato}" style=" width : 126px;">
							<f:selectItem itemLabel="Accettato" itemValue="Accettato" />
        					<f:selectItem itemLabel="Evaso" itemValue="Evaso" />
       				 		<f:selectItem itemLabel="In Attesa" itemValue="In Attesa" />
						</h:selectOneMenu>
					
						
						<h:outputText id="importoTotale" value="Importo Totale" />
						<h:inputText value="#{tab.object.importoTotale}" style=" width : 125px;"/>
						
					
					</h:panelGrid>
				</h:panelGroup>
				
				
			</h:panelGrid>
			
		</fieldset>
	</ui:define>
	
	
	
	
</ui:composition>